<template>
	<view class="content">
		<block v-for="(typeitem,indextype) in carList" :key="typeitem.id">
		<view class="content-car " v-for="(item,index) in typeitem.car" 
		:key="index" @click="selectCar(item,typeitem,indextype,index)">
			<view class="flex-content m-t20 m-r20">
				<image :src="item.cover" mode="widthFix"></image>
			</view>
			
			<view class="wenzi flex-content  m-t20 m-r20">
				{{item.car_name}}
			</view>
			</view>
			</block>
	</view>
</template>

<script>
		import {currentPage} from '@/utils/tools.js'
	import {getIndexCar} from "@/api/car.js"
	export default {
		data() {
			return {
				carList:[]
			}
		},
		async onLoad() {
			await this.getCarList()
		},
		
		methods: {
	selectCar(item,typeitem,indextype,index){ 
		
		let pages = getCurrentPages();
		
		if(pages[pages.length - 2].$page.fullPath=="/pages/index/index"){
			let indexcar=indextype+1
			uni.$emit("selectCarType",{
				cartType:indexcar,
				carType:index
			})
			uni.navigateBack({
				
			})
		return	
		}
		  let beforePage = pages[pages.length - 2];

		beforePage.$vm.info.car_category_id =typeitem.id;
		 beforePage.$vm.info.car_id =item.id;
		  beforePage.$vm.typeValue=typeitem.category_name+'——'+item.car_name
		  
		  uni.navigateBack({
		  	
		  })
	},
			async getCarList(){
						let _this=this
				let res= await getIndexCar()
			  this.carList=res.data.lists
				
			}
		}
	}
</script>

<style lang="scss" scoped>
.content{
	width: 100%;
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	
	.content-car{
		border-bottom: 2rpx solid #E6E5E5 ;
		height: 222rpx;
		padding-top: 50rpx;
		
	
		padding-bottom: 20rpx;
		background-color: #FFFFFF;
		width: 33.3%;
		image{
			width: 80%;
		}
	}
	.wenzi{
		margin-top: 20rpx;
	}
}
.content-car:nth-child(1){
	image{
		width: 50%;
	}
}
.content-car:nth-last-child(1){
	image{
		width: 90%;
	}
}
</style>
